import sqlite3
import csv
from collections import namedtuple


HotelInfo = namedtuple("HotelInfo", ["id", "name","image","price","location", "score"])

con = sqlite3.connect("./hotel_spyder/hotel.db")
cur = con.cursor()

with open('./hotel_spyder/output.csv', 'r') as f:
    reader = csv.reader(f.readlines()[1:])
    for line in reader:
        try:
            cur.execute("INSERT INTO hotel(id, name, image_url, price, location, score) values({}, '{}', '{}', {}, '{}', {});".format(*tuple(line)))
        except sqlite3.IntegrityError:
            print(line[0])
con.commit()


cur.close()
con.close()